package com.lhy.tool.database.converter.sqlserver;

import com.lhy.tool.database.DbColumnType;
import com.lhy.tool.database.converter.common.AbstractDbColumnTypeMapping;
import com.lhy.tool.database.converter.ColumnTypeMappingRule;
import org.springframework.stereotype.Component;

public class SqlServerColumnTypeMapping extends AbstractDbColumnTypeMapping {

    public SqlServerColumnTypeMapping() {
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("char") || columnType.contains("text") || columnType.contains("xml"), (columnType) -> DbColumnType.STRING));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("bigint"), (columnType) -> DbColumnType.LONG));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("bit"), (columnType) -> DbColumnType.BOOLEAN));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("int"), (columnType) -> DbColumnType.INTEGER));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("float") || columnType.contains("real"), (columnType) -> DbColumnType.FLOAT));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("decimal") || columnType.contains("numeric"), (columnType) -> DbColumnType.DOUBLE));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("money"), (columnType) -> DbColumnType.BIG_DECIMAL));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("date") || columnType.contains("time"), (columnType) -> DbColumnType.DATE));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("binary") || columnType.contains("image"), (columnType) -> DbColumnType.BYTE_ARRAY));
    }

}
